package com.lagou.studentsystem.servlet;

import com.lagou.studentsystem.dao.ClassesDao;
import com.lagou.studentsystem.dao.Impl.ClassesDaoImpl;
import com.lagou.studentsystem.model.Classes;
import com.lagou.studentsystem.model.Student;
import com.lagou.studentsystem.service.StudentService;
import com.lagou.studentsystem.service.impl.StudentServiceImpl;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "InsertClassesServlet",urlPatterns = "/InsertClasses")
public class InsertClassesServlet extends HttpServlet {

    private ClassesDao classesDao = new ClassesDaoImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        String c_id = request.getParameter("c_id");
        String c_name = request.getParameter("c_name");
        String c_teacher = request.getParameter("c_teacher");
        String c_slogan = request.getParameter("c_slogan");
        String c_grade = request.getParameter("c_grade");
        String c_size = request.getParameter("c_size");
        Classes classes = new Classes(c_id,c_name,Integer.parseInt(c_grade),c_teacher,c_slogan,Integer.parseInt(c_size));
        int i = classesDao.insertClasses(classes);
        if (i!=0){
            RequestDispatcher findAllStudent = request.getRequestDispatcher("findClassesAll");
            findAllStudent.forward(request,response);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
